<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        class Promise {
            promiseState = 'ing'
            promiseResult = null
            constructor(callback) {
                const resolve = (data) => {
                    if (this.promiseState !== 'ing') return
                    this.promiseState = 'success'
                    this.promiseResult = data
                }
                const reject = (data) => {
                    if (this.promiseState !== 'ing') return
                    this.promiseState = 'error'
                    this.promiseResult = data
                }
                callback(resolve, reject)
            }
        }
        // 原型方法
        Promise.prototype.then = function () { }
        Promise.prototype.catch = function () { }
        Promise.prototype.finally = function () { }
        // 静态方法
        Promise.resolve = function () { }
        Promise.reject = function () { }
        Promise.all = function () { }
        Promise.race = function () { }
        Promise.allSettled = function () { }
        Promise.any = function () { }

        console.log('------------------------------')

        const p = new Promise((resolve, reject) => {
            console.log('进行中', 11111111)
            resolve(111)
            reject(222)
        })
        p
        .then(
            res => {
                console.log('成功了', res)
            },
            err => {
                console.log('失败了', err)
            })
    </script>
</body>
</html>